import * as tools from './tools.js';
import '../sass/common.scss';
import Pagination from '../mod/lib/webpagonation.js';
import {initHeaderFooter} from './gopLib/initHeaderFooter';
jQuery.support.cors = true;
let DATA_GROUP = [];
$(function () {
    $('.help_').addClass('active');
    initPlatForm();
    initHeaderFooter();
    $('.platInfo_list').on('click', '.plat_item', function() {
        window.location.href = './platInfoDetail.html?id=' + $(this).attr('data-id');
    })
    
});


function initPlatForm() {
    $.ajax({
        url: tools.apiUrl + 'rolledImage/imgList',
        type: 'post',
        contentType: 'text/xml',
        data: 'PLATFORM',
        success: function (res) {
            let data = res.data;
            if (res.code == '200') {
                let PAG = new Pagination({
                    data : renderPlatForm(data),
                    pageSize: 5,
                    $trg: $('.platInfo_content'),
                    $content: $('.platInfo_list')
                })
            }
        }
    });
}

function renderPlatForm(data) {
    let _info = '';
    return data.map((val, index) => {
        return `
            <div class="plat_item" data-id="${val.id}">
                <div class="plat_item_h">
                    <span>0${++index}</span>
                    <p>${tools.timeModify((new Date(val.createTime)).format('yyyy-MM-dd'))}</p>
                </div>
                <div style="width:140px;margin-right:30px">
                    <div class="plat_cover" style="background:url('${val.url}');background-size:cover">
                        
                    </div>
                </div>
        
                <div class="plat_item_body">
                    <p class="plat_item_body_h">${val.name}</p>
                    <p class="plat_item_body_b">${val.content}</p>
                </div>
            </div>
            `
    });
}